//
//  LocaizeTool.m
//  _HealthDetector
//
//  Created by  on 2021/4/15.
//  Copyright © 2021 . All rights reserved.
//

#import "LocalizeTool.h"
#import "LocalizeKeys.h"

@implementation LocalizeTool
+(NSString *)localizeFromTables:(NSString *)key Tables:(NSArray<NSString *> *)tables {
    if (!tables.count) {
        return nil;
    }
    NSString *locaString = nil;
    for (NSString *tableName in tables) {
        
        NSString *strTmp = [NSBundle.mainBundle localizedStringForKey:key value:nil table:tableName];
        locaString = strTmp;
        if ([strTmp isEqual:key]) {
            continue;
        } else {
            break;
        }
    }
//    NSLocalizedStringFromTableInBundle();
    return locaString;
    
    
}



+(void)checkKeyStringsTables {
#if DEBUG
    NSArray<NSString *> * tables = @[@"Localizable"];
    if (!tables.count) {
        return ;
    }
    
    NSArray<NSString *> *keys = [self keys];
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        for (NSString *key in keys) {
            
            NSString *locaString = nil;
            for (NSString *tableName in tables) {
                
                NSString *strTmp = [NSBundle.mainBundle localizedStringForKey:key value:nil table:tableName];
                locaString = strTmp;
                if ([strTmp isEqual:key]) {
                    continue;
                } else {
                    break;
                }
            }
            
            if ([locaString isEqual:key]) {
                DebugNSLog(@"checkKeys 未找到  key: %@", key);
            }
        }
        DebugNSLog(@"checkKeys 检查结束");

    });
    
   

    
//    NSLocalizedStringFromTableInBundle();
    return;
    
#endif
}

+(NSArray<NSString *> *)keys {
    
    return nil;
}

@end
